package com.black.platform.position.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.black.common.web.ApiResponse;
import com.black.common.web.ApiResponseBuilder;
import com.black.common.web.PageQuery;
import com.black.platform.position.po.Position;
import com.black.platform.position.service.handler.PositionHandlerService;
import com.black.platform.position.vo.PositionRoleVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("position")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PositionController {

    private final PositionHandlerService positionHandlerService;

    @GetMapping("id/{id}")
    public ApiResponse<PositionRoleVo> getById(@PathVariable("id") Long id) {
        return ApiResponseBuilder.ok(positionHandlerService.getPositionRoleVoByPositionId(id));
    }

    @GetMapping("allList")
    public ApiResponse<List<Position>> list() {
        return ApiResponseBuilder.ok(positionHandlerService.getAllPositions());
    }

    @PostMapping("search")
    public ApiResponse<IPage<Position>> search(@RequestBody PageQuery<Position> searchVo) {
        return ApiResponseBuilder.ok(positionHandlerService.search(searchVo));
    }

    @PostMapping("save")
    public ApiResponse<Boolean> save(@RequestBody PositionRoleVo positionRoleVo) {
        return ApiResponseBuilder.ok(positionHandlerService.saveOrUpdate(positionRoleVo));
    }

    @PostMapping("update")
    public ApiResponse<Boolean> update(@RequestBody PositionRoleVo positionRoleVo) {
        return ApiResponseBuilder.ok(positionHandlerService.saveOrUpdate(positionRoleVo));
    }

}
